package ms.unicorn.util;

import java.net.URL;

import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.internal.util.BundleUtility;


@SuppressWarnings("restriction")
public class PluginUtil {
	
	public static URI getResourceURI(String pluginId, String resourcePath) {
		return URI.createPlatformPluginURI("/" + pluginId + "/" + resourcePath, true);
	}
	
	public static ImageDescriptor getImageDescriptor(String pluginId, String imagePath) {
		if (pluginId == null || imagePath == null)
			return null;
		URL url = null;
					
		url = BundleUtility.find(pluginId, imagePath);
		if (url != null) return ImageDescriptor.createFromURL(url);
		
		return null;
	}
	
	public static ImageDescriptor getImageDescriptor(String pluginId, String imagePath, ImageDescriptor defaultImage) {
		ImageDescriptor value = getImageDescriptor(pluginId, imagePath);
		if (value == null)
			value = defaultImage;
		return value;
	}
}
